if (!jsx3.lang.Class.forName("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.CooOrgLoanAssistBaseinfo")) {

    /**
     * Define the <code>name of class</code> class.
     * This class inherit from <code>jsx3.gui.Block<code> GUI class.
     */
    jsx3.Class.defineClass("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.CooOrgLoanAssistBaseinfo", ux.megatron.gui.WizardPanel, null, function(objRoot){
        objRoot.prototype.btnAdd = null; //add button
        objRoot.prototype.btnEdit = null; //edit button
        objRoot.prototype.btnDelete = null; //delete button
        objRoot.prototype.matrix = null;//matrix
        objRoot.prototype.canEdit = false;//whether the record can edit
        objRoot.prototype.blkExpend = null;//the panel which contain the buttons "save&cancel"
        objRoot.prototype.initRecords=null;//save the content befor edit
        objRoot.prototype.wizard=null;//save the content befor edit
        objRoot.prototype.partyId=null;
        /*
         * This method will be called after UI file has deserialized.
         */
        objRoot.prototype.onAfterDeserialize = function(){
        	

			
        }
		objRoot.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML) {
			//call constructor for super class (the super expects the name of the object and the function that it is an instance of)
			this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
		};

		objRoot.prototype.initialize = function(msg) {
			this.wizard = this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgWizard");
			var me=this;
			//load the ORG_LEVEL
			//ux.cdb.admin.CommonCache.loadCache(['ORG_LEVEL','REGION_CATEG','AGENT_BANK'], me,me.cacheLoaded);
			this.cacheLoaded();
			//this.wizard = this.getAncestorOfType("ux.megatron.gui.SteppedWizard");
		}
		/*
		 * call back function when cache loaded
		 */
		objRoot.prototype.cacheLoaded = function(){
		//get the cache
			var cache = ux.cdb.admin.CommonCache.getInstance();
			var me=this;
			this.getDescendantOfName("blkCooOrgLevel").getDescendantOfName("selValue").setSourceXML(cache.getCache('CommonCache_ORG_LEVEL'));
			this.getDescendantOfName("blkAreaCode").getDescendantOfName("selValue").setSourceXML(cache.getCache('CommonCache_REGION_CATEG'));
			this.getDescendantOfName("blkFirstBank").getDescendantOfName("selValue").setSourceXML(cache.getCache('CommonCache_AGENT_BANK'));
			if (this.wizard.isEdit)
			{//load the data from server

				ux.megatron.util.Dwr.callDwr("MaintainCooperOrgUCC", "getStudentAidCenter", [this.wizard.orgId], me, me.baseinfoLoaded);

			}
			this.focus();
		}
		/*
		 * received message contain the baseinfo
		 */
		objRoot.prototype.baseinfoLoaded=function(message)
		{
			console.log("\r\r\r\t【got the baseinfo from server】\r"+ux.megatron.util.JSON.JSONtoString(message)+"\r");
			this.getDescendantOfName("blkAssistBaseinfoField").setDataByObject(message.content.data[0]);
			this.wizard.baseinfoObj=message.content.data[0];
			;//save area code
			//remove the attribute avoid auto apply
			//message.content.data[0].logicalAreaCode=null;
			
			this.getDescendantOfName("blkCooOrgLevel").getDescendantOfName("selValue").setValue(message.content.data[0].orgLevelCode);
			this.regionSelected(this.getDescendantOfName("blkCooOrgLevel").getDescendantOfName("selValue"));
			//the folow temp dispose the areacode,because some item only have province
			var areaCode=message.content.data[0].logicalAreaCode
			var level=this.getDescendantOfName("blkCooOrgLevel").getDescendantOfName("selValue").getText();
			
			this.applyAreaDate(level,areaCode);


		}
		
		//set the area date
		objRoot.prototype.applyAreaDate=function(level,val)
		{
			var me = this;
			var docArea = ux.megatron.Main.getServer().getCache().getDocument('Area_doc');
			var sel3Record = docArea.getRecordNode(val);
			var sel2Record = sel3Record.getParent();
			var sel1Record = sel2Record.getParent();
			
			//console.log(docArea);
			try{
				
				if (level=="省") {
					sel1Record = docArea.getRecordNode(val);
				
				}
				else if (level=="市")
				{
					sel2Record = docArea.getRecordNode(val);
			 		sel1Record = sel3Record.getParent();
				}
				else
				{
					sel3Record = docArea.getRecordNode(val);
			 		sel2Record = sel3Record.getParent();
			 		sel1Record = sel2Record.getParent();
				}
				
			}catch(ex){
				throw 'You specified a error area code ,the code is not exists,code is:'+val;
			}

			//console.log('sels,from 1,2,3:',sel1Record,sel2Record,sel3Record);
			//Bull shit code,just for working....lost my face.
			var selDoc,children,child;
			var selects = this.getDescendantOfName("lblRegRegionValue").getDescendantsOfType('jsx3.gui.Select');
			for(var i=0;i<selects.length;i++){
				var sel = selects[i];
				var scriptEvent = sel.getEvent(jsx3.gui.Interactive.SELECT);
				var recordNode = eval('sel'+(i+1).toString()+'Record');
				if (recordNode==null)
				{
					continue;
				}
				if(i == 0){
					sel.setValue(recordNode.getAttribute('jsxid'));
				}else{
					selDoc = jsx3.xml.CDF.Document.newDocument();
					children = recordNode.getParent().getChildNodes();					
					for(j=0;j<children.size();j++){
						child = children.get(j).cloneNode(false);
						selDoc.insertRecordNode(child);
					}					
					sel.setSourceXML(selDoc);
					sel.setValue(recordNode.getAttribute('jsxid'),true);
				}
				sel.setEvent(scriptEvent,jsx3.gui.Interactive.SELECT);
			}
		}
		

		objRoot.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
		
			return null; // return "NONE" to not next panels
		}

		objRoot.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			//validate the data
			var dataField=this.getDescendantOfName("blkAssistBaseinfoField");
			if (dataField.doValidate()!=null)
			{//Validate fail
				this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.Builder").setWarnMessage(ux.megatron.Main.getServer().getDynamicProperty("@cdb@Mechanism@CooOrg@InputValidateNotice"));
				return "NONE";
			}
			this.wizard.step4=true;
			return null; // return "NONE" to not advance panels
		}
		objRoot.prototype.onFinish = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {

			//validate the datahaod
			var dataField=this.getDescendantOfName("blkAssistBaseinfoField");
			if (dataField.doValidate()!=null)
			{//Validate fail
				this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.Builder").setWarnMessage(ux.megatron.Main.getServer().getDynamicProperty("@cdb@Mechanism@CooOrg@InputValidateNotice"));
				return "NONE";
			}

			//save the organization's base info
			this.saveSummary();

			/*
			var data=this.getDescendantOfName("blkAssistBaseinfoField").getDataAsObject();
			var me=this;
			alert(ux.megatron.util.JSON.JSONtoString(data));
			ux.megatron.util.Dwr.callDwr("AddCooperOrgUCC", "saveStudentAidCenter",[data], me, me.baseinfoSaved);
			alert("finish")
			*/
			return null; // return "NONE" to not advance panels
		}
		//when data saved
		objRoot.prototype.baseinfoSaved=function(objEvent)
		{
		}
		//call the service operation to save baseinfo
		objRoot.prototype.saveSummary=function()
		{
			if (this.wizard==null)
			{
				this.wizard = this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgWizard");
			}
			var dataField=this.wizard.getDescendantOfName("blkSummary");
			var me = this;
			var summaryInfo=dataField.getDataAsObject();
			summaryInfo.cooperOrgTypeCode="2401"; //学生资助中心代码
			summaryInfo.branchCode= this.wizard.internalOrgId;
			var field;
			this.wizard.orgName=summaryInfo.chnFullName;
		
			
			if (!this.wizard.isEdit) {
				//add mode save the info
				ux.megatron.util.Dwr.callDwr("AddCooperOrgUCC", "saveCooperOrgGeneralInfo", [summaryInfo], me, me.summarySaved);
			}
			else{
				//if edit mode,get the partyid from summary
				this.partyId=summaryInfo.partyId;
				//edit mode change the info
				//merge the edited message with the original message
				console.log("\r\r\t【original object of the cooperation organization summery】\r"+ux.megatron.util.JSON.JSONtoString(this.wizard.summaryObj)+"\t");
				for (field in summaryInfo)
				{
					this.wizard.summaryObj[field]=summaryInfo[field];
				}
				console.log("\r\r\t【After Edit object of the cooperation organization summery】\r"+ux.megatron.util.JSON.JSONtoString(this.wizard.summaryObj)+"\t");
				ux.megatron.util.Dwr.callDwr("MaintainCooperOrgUCC", "updateCooperOrgGeneralInfo", [this.wizard.summaryObj], me, me.summarySaved);
			}
		}
		//baseinfo saved ,call operation to save address info
		objRoot.prototype.summarySaved=function(message)
		{
			console.log(ux.megatron.util.JSON.JSONtoString(message));
			if (!this.wizard.isEdit) 
			{//if current mode is edit partyId come form back message
				this.partyId = message.content.data[0].partyId;
			}
			//next save address info
			this.saveAddressInfo(message);
		}
		
		//call the service operation to save address info
		objRoot.prototype.saveAddressInfo=function(message)
		{

			console.log("\r\r\t"+ux.megatron.util.JSON.JSONtoString(message));
			// to save address info		
			if (this.wizard.getDescendantOfName("blkRegAddress")) 
			{//user already visited the address info, to save address 
				var regAddress = this.wizard.getDescendantOfName("blkRegAddress").getDataAsObject();
				var officeAddress = this.wizard.getDescendantOfName("blkOfficeAddress").getDataAsObject();
				
				
				regAddress.partyId = this.partyId;
				regAddress.addrId = this.wizard.regAddrId;
				regAddress.addrTypeCode = "04";
				regAddress.postalCode = null;
				regAddress.website = null;
				regAddress.emailAddr = null;
				regAddress.phoneNbr = null;
				regAddress.faxNbr = null;
				
				officeAddress.partyId = this.partyId;
				officeAddress.addrId = this.wizard.offAddrId;
				officeAddress.addrTypeCode = "01";
				
				
				
				
				var data;
				data=[regAddress,officeAddress];
				
				var field;
				var i;

				
				
				var me = this;
				if (this.wizard.isEdit) 
				{	
					
					/*data =this.wizard.addressObj;
					console.log("\r\r\t【the original address info】"+ux.megatron.util.JSON.JSONtoString(data));
					//return the object as original
					for (i=0;i<2;i++)
					{
						if (data[i].addrTypeCode=="0")
						{
							for(field in regAddress)
							{
								data[i][field]=regAddress[field];
							}
						}
						else
						{
							for(field in officeAddress)
							{
								data[i][field]=officeAddress[field];
							}
						}
					}
					console.log("\r\r\t【the edited address info】"+ux.megatron.util.JSON.JSONtoString(data));
					*/
					//current mode is edit existed address
					ux.megatron.util.Dwr.callDwr("MaintainCooperOrgUCC", "updateBatchAddress", [data], me, me.addressSaved);
				}
				else 
				{
					
					//current mode is add new address
					ux.megatron.util.Dwr.callDwr("AddCooperOrgUCC", "saveBatchAddress", [data], me, me.addressSaved);
					
				}
			}
			else
			{//user never visit address into,jump to save linkman info
				this.addressSaved(message);
			}
		}
		
		//address info saved,received the back message from server
		objRoot.prototype.addressSaved=function(message)
		{


			//address info saved,save likeman info
			if (this.wizard.getDescendantOfName("mtxEditLinkman")==null) 
			{//if user not fill linkman info
				this.saveBaseinfo(message);
				return;
			
			}
			var record=this.wizard.getDescendantOfName("mtxEditLinkman").getXML().getChildNodes();

			var data=new Array();
			var me=this;
			for(var i=0;i<record.size();i++)
			{
				if (record.get(i).getAttribute("jsxIsModify") == "true") {
					if (record.get(i).getAttribute("jsxIsNew") == "true") {
						data.push({
							partyId:this.partyId,
							contactPersonId:null,
							contactPersonTypeCode: record.get(i).getAttribute("jsxtype"),//联系人类型
							contactPersonName: record.get(i).getAttribute("jsxname"),//联系人姓名
							contactPersonFixPhone: record.get(i).getAttribute("jsxtelephone"),//固定电话
							contactPersonMobNum: record.get(i).getAttribute("jsxcellphone"),//移动电话
							contactPersonEmail: record.get(i).getAttribute("jsxemail"), //电子邮件	
							ContactFaxNbr:"" //传真	
						});
					}
					else
					{
						data.push({
							partyId:this.partyId,
							contactPersonId: record.get(i).getAttribute("jsxid"),//联系人ID
							contactPersonTypeCode: record.get(i).getAttribute("jsxtype"),//联系人类型
							contactPersonName: record.get(i).getAttribute("jsxname"),//联系人姓名
							contactPersonFixPhone: record.get(i).getAttribute("jsxtelephone"),//固定电话
							contactPersonMobNum: record.get(i).getAttribute("jsxcellphone"),//移动电话
							contactPersonEmail: record.get(i).getAttribute("jsxemail"), //电子邮件
							ContactFaxNbr:"" //传真	
						});
					}
				}
				
			}
			console.log("\n\n\t send linkman message to save "+ux.megatron.util.JSON.JSONtoString(data));
			if (data.length > 0) {
				if (this.wizard.isEdit) {
					//current mode is edit  call upate
					ux.megatron.util.Dwr.callDwr("MaintainCooperOrgUCC", "updateContactPersonList", [data], me, me.linkmanSaved);
				}
				else{
					//current mode is add call save
					ux.megatron.util.Dwr.callDwr("AddCooperOrgUCC", "saveContactPerson", [data], me, me.linkmanSaved);
				}
			}
			else
			{//no likeman info need to save,save the baseinfo
				this.saveBaseinfo(message);
			}
		}
		//receive the back message about save likeman info
		objRoot.prototype.linkmanSaved = function(message) {

			//likeman message saved, to save baseinfo
			this.saveBaseinfo(message);
			
		}
		//call the server operation to save baseinfo
		objRoot.prototype.saveBaseinfo=function(message)
		{
			if (this.getDescendantOfName("blkAssistBaseinfoField")==null)
			{//user not edit baseinfo
				this.baseinfoSaved(message);
			}
			var data=this.getDescendantOfName("blkAssistBaseinfoField").getDataAsObject();
			var me=this;
			
			if (this.getDescendantOfName("selValue3").getDisplay()!=jsx3.gui.Block.DISPLAYNONE)
			{
				data.logicalAreaCode=this.getDescendantOfName("selValue3").getValue();
			}
			else
			{
				if (this.getDescendantOfName("selValue2").getDisplay()!=jsx3.gui.Block.DISPLAYNONE)
				{
					data.logicalAreaCode=this.getDescendantOfName("selValue2").getValue();
				}
				else
				{
					data.logicalAreaCode=this.getDescendantOfName("selValue1").getValue();
				}
			}
			
			//mergy step1&4
			console.log("\r\r\t before merge:"+ux.megatron.util.JSON.JSONtoString(data));
			
			var summary=this.wizard.getDescendantOfName("blkSummary").getDataAsObject();
			//merge the baseinfo and summaryinfo to avoid the baseinfo mantling the summaryinfo beacause in the database they are same record
			var field;
			for(field in summary)
			{
				data[field]=summary[field];
			}
			data.partyId=this.partyId;
			data.cooperOrgTypeCode="2401";//code of 学生资助中心
			data.branchCode= this.wizard.internalOrgId;
			data.parentOrgId=this.getDescendantOfName("selValue1").getValue();//上级资助中心id
			console.log("\r\r\t after merge:"+ux.megatron.util.JSON.JSONtoString(data));
			if (this.wizard.isEdit) {
				//current mode is edit
				//merge the original object and the Edited Object
				console.log("\r\r\t【original object of the cooperation organization baseinfo】\r"+ux.megatron.util.JSON.JSONtoString(this.wizard.baseinfoObj)+"\t");
				for (field in data) 
				{
					this.wizard.baseinfoObj[field]=data[field];
				}
				console.log("\r\r\t【edited object of the cooperation organization baseinfo】\r"+ux.megatron.util.JSON.JSONtoString(this.wizard.baseinfoObj)+"\t");
				ux.megatron.util.Dwr.callDwr("MaintainCooperOrgUCC", "updateStudentAidCenter", [this.wizard.baseinfoObj], me, me.baseinfoSaved);
			}
			else {
				//current mode is add
				ux.megatron.util.Dwr.callDwr("AddCooperOrgUCC", "saveStudentAidCenter", [data], me, me.baseinfoSaved);
			}

		}
		
		
		//received the back message about save baseinfo
		objRoot.prototype.baseinfoSaved = function(message){
			//all saved
			if (this.wizard.isEdit) 
			{
				
				if (message.res.flag == 1) 
				{
					alert(ux.megatron.Main.getServer().getDynamicProperty("@cdb@Mechanism@CooOrg@ModifyCooOrgNotice"));
				}
				ux.megatron.Main.getServer().getBodyBlock().getDescendantsOfType("ux.cdb.admin.mechanism.cooOrg.CooOrg")[0].onRefresh(this.wizard.isEdit);
			}
			else
			{
				//ux.megatron.Main.getServer().getBodyBlock().getDescendantsOfType("ux.cdb.admin.mechanism.cooOrg.CooOrg")[0].getDescendantOfName("blkSearchName").getDescendantOfName("txtValue").setValue(this.wizard.orgName);
				//ux.megatron.Main.getServer().getBodyBlock().getDescendantsOfType("ux.cdb.admin.mechanism.cooOrg.CooOrg")[0].onSearch();
				if (message.res.flag == 1) 
				{
					alert(ux.megatron.Main.getServer().getDynamicProperty("@cdb@Mechanism@CooOrg@AddCooOrgNotice"));
				}
			}
			this.wizard.doClose();
		}

		objRoot.prototype.onRevert = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			return null; // return "NONE" to not last status
		}

		objRoot.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgWizard").onClose();
			return null; // return "NONE" to not advance panels
		}

		objRoot.prototype.onCustomNav = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			return null; // return "NONE" to not advance panels
		}
	
		objRoot.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL) {
			if(!this.getChild(0)) {
				var me = this;
				ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin","ux/cdb/admin/mechanism/cooOrg/CooOrgLoanAssist/builder/step4/ui/CooOrgLoanAssistBaseinfoContent.xml",me,me.initialize);
			}
			return null; // return "NONE" to not advance panels
		}

		objRoot.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL) {
			return null; // return "NONE" to not advance panels
		}
		
		objRoot.prototype.regionSelected=function(obj)
		{
			var selValue2=this.getDescendantOfName("selValue2");
			var selValue3=this.getDescendantOfName("selValue3");
			if (obj.getText()=="省") {
				selValue2.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
				selValue3.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);

				return;
			}
			else if (obj.getText()=="市")
			{
				selValue2.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
				selValue3.setDisplay(jsx3.gui.Block.DISPLAYNONE,true);

				return;	
			}
			else
			{
				selValue2.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
				selValue3.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
				return;
	
			}
			
		}
		
		
    });
}
